import {
	myRequest
} from '../http.js';
import CryptoJS from 'crypto-js';
// 登录
/**
 *加密处理
 */
function encryption(src, keyWord) {
	const key = CryptoJS.enc.Utf8.parse(keyWord);
	// 加密
	var encrypted = CryptoJS.AES.encrypt(src, key, {
		iv: key,
		mode: CryptoJS.mode.CFB,
		padding: CryptoJS.pad.NoPadding,
	});
	return encrypted.toString();
}
// 登录
export function doLogin(config) {
	let encPassword = encryption(config.password, 'thanksjxtechsand');
	config.password = encPassword
	// console.log("config", config)
	return myRequest({
		url: 'oauth2/token',
		method: 'POST',
		data: config,
		contentType: "application/x-www-form-urlencoded"
		// contentType: "application/json"
	})
}
// 退出登录
export function loginOut() {
	return myRequest({
		url: 'token/logout',
		method: 'DELETE',
	})
}
// 获取登录用户的业务端列表
export function getBusinessList(config) {
	return myRequest({
		url: `app/user/getAppByUserId/${config.userId}`
	})
}
// 获取用户信息
export function getUserInfo(userId) {
	return myRequest({
		url: `app/user/userDetail/${userId}`
	})
}
// 修改密码
export function updatePwd(data) {
	return myRequest({
		url: 'companyAccount/updatePassWord',
		method: 'POST',
		data
	})
}